package com.industrial.premu.controller;

import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.premu.domain.PreMuCompanyRename;
import com.industrial.premu.service.IPreMuCompanyRenameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 企业更名Controller
 *
 * @author ruoyi
 * @date 2024-02-05
 */
@RestController
@RequestMapping("/rename")
public class PreMuCompanyRenameController extends BaseController {
    @Autowired
    private IPreMuCompanyRenameService preMuCompanyRenameService;

    /**
     * 查询企业更名列表
     */
    @RequiresPermissions("cm:rename:list")
    @GetMapping("/list")
    public TableDataInfo list(PreMuCompanyRename preMuCompanyRename) {
        startPage();
        List<PreMuCompanyRename> list = preMuCompanyRenameService.selectPreMuCompanyRenameList(preMuCompanyRename);
        return getDataTable(list);
    }

    /**
     * 导出企业更名列表
     */
    @RequiresPermissions("cm:rename:export")
    @Log(title = "企业更名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PreMuCompanyRename preMuCompanyRename) {
        List<PreMuCompanyRename> list = preMuCompanyRenameService.selectPreMuCompanyRenameList(preMuCompanyRename);
        ExcelUtil<PreMuCompanyRename> util = new ExcelUtil<PreMuCompanyRename>(PreMuCompanyRename.class);
        util.exportExcel(response, list, "企业更名数据");
    }

    /**
     * 获取企业更名详细信息
     */
    @RequiresPermissions("cm:rename:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(preMuCompanyRenameService.selectPreMuCompanyRenameById(id));
    }

    /**
     * 新增企业更名
     */
    @RequiresPermissions("cm:rename:add")
    @Log(title = "企业更名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PreMuCompanyRename preMuCompanyRename) {
        return toAjax(preMuCompanyRenameService.insertPreMuCompanyRename(preMuCompanyRename));
    }

    /**
     * 修改企业更名
     */
    @RequiresPermissions("cm:rename:edit")
    @Log(title = "企业更名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PreMuCompanyRename preMuCompanyRename) {
        return toAjax(preMuCompanyRenameService.updatePreMuCompanyRename(preMuCompanyRename));
    }

    /**
     * 删除企业更名
     */
    @RequiresPermissions("cm:rename:remove")
    @Log(title = "企业更名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(preMuCompanyRenameService.deletePreMuCompanyRenameByIds(ids));
    }

    /**
     * <p>
     *     更改名称企业名称
     * </p>
     * @param companyRename
     */
    @PostMapping("/chanageName")
    public AjaxResult chanage(@RequestBody PreMuCompanyRename companyRename){
        preMuCompanyRenameService.chanage(companyRename);
        return AjaxResult.success();
    }
}